﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PigletUpdate.aspx.cs" Inherits="OnlineManagement.Web.pages.PigletUpdate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../resources/css/jquery.ui.all.css" rel="stylesheet" type="text/css" />
    <script src="../resources/scripts/jquery-1.10.2.js" type="text/javascript"></script>
     <script src="../resources/scripts/jquery.ui.core.js" type="text/javascript"></script>
     <script src="../resources/scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
     <script src="../resources/scripts/jquery.ui.widget.js" type="text/javascript"></script>
     <script src="../resources/scripts/jquery.ui.datepicker-zh-TW.js" type="text/javascript"></script>
     <script src="../resources/scripts/myAjax.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#<%=txtCastrateDate.ClientID %>").datepicker($.datepicker.regional["zh-TW"]).datepicker("option", "dateFormat", "yy-mm-dd");
            $("#<%=ddlPhaseToID.ClientID %>").attr("style", "display:none");
            $("#<%=ddlPigType.ClientID %>").attr("style", "display:none");
            $("#penSetting").attr("style", "display:none");


            var checked = $("#<%=cbNoCastrate.ClientID %>").attr("checked");
            if (checked) {
                $("#pCastrate").attr("style", "display:none");
            } else {
                $("#pCastrate").attr("style", "display:block");
            }


            $("#changPhase").click(function () {
                var style = $("#<%=ddlPhaseToID.ClientID %>").attr("style");
                if (style == "display:none") {
                    $("#<%=ddlPhaseToID.ClientID %>").attr("style", "display:block");
                } else {
                    $("#<%=ddlPhaseToID.ClientID %>").attr("style", "display:none");
                }
            });
            $("#changPigType").click(function () {
                var style = $("#<%=ddlPigType.ClientID %>").attr("style");
                if (style == "display:none") {
                    $("#<%=ddlPigType.ClientID %>").attr("style", "display:block");
                } else {
                    $("#<%=ddlPigType.ClientID %>").attr("style", "display:none");
                }
            });

            $("#<%=cbNoCastrate.ClientID %>").change(function () {
                if (this.checked) {
                    $("#pCastrate").attr("style", "display:none");
                    $("#<%=cbIsCastrate.ClientID %>").attr("checked", false);
                } else {
                    $("#pCastrate").attr("style", "display:block");
                    $("#<%=cbIsCastrate.ClientID %>").attr("checked", true);
                }
            });
            $("#<%=cbIsCastrate.ClientID %>").change(function () {
                if (this.checked) {
                    $("#pCastrate").attr("style", "display:block");
                    $("#<%=cbNoCastrate.ClientID %>").attr("checked", false);
                } else {
                    $("#pCastrate").attr("style", "display:none");
                    $("#<%=cbNoCastrate.ClientID %>").attr("checked", true);
                }
            });

            $("#<%=ddlPhaseToID.ClientID %>").change(function () {
                var id = $(this).val();
                var value = $(this).find("option:selected").text();
                $("#<%=hfPhaseToID.ClientID %>").val(id);
                $("#<%=lbPhaseName.ClientID %>").text(value);
                if (id > 2) {
                    $("#penSetting").attr("style", "display:block");
                } else {
                    $("#penSetting").attr("style", "display:none");
                }
            });
            $("#<%=ddlPigType.ClientID %>").change(function () {
                var id = $(this).val();
                var value = $(this).find("option:selected").text();
                $("#<%=lbPigType.ClientID %>").text(value);
                $("#<%=hfPigTypeID.ClientID %>").val(id);

            });
            $("#<%=ddlPigPen.ClientID %>").change(function () {
                var id = $(this).val();
                $("#<%=hfpigPenID.ClientID %>").val(id);
            });


            $("#btnSave").click(function () {
                var pigletId = $("#<%=hfPigletID.ClientID %>").val();
                var phaseFromId = '<%=_phaseFromID %>';
                var phaseToID = $("#<%=hfPhaseToID.ClientID %>").val();
                var pigTypeID = $("#<%=hfPigTypeID.ClientID %>").val();
                var pigPenID = $("#<%=hfpigPenID.ClientID %>").val();
                var castrateDate = "";
                var checked = $("#<%=cbIsCastrate.ClientID %>").attr("checked");
                if (checked) {
                    castrateDate = $("#<%=txtCastrateDate.ClientID %>").val();
                    if (castrateDate == undefined || castrateDate == "") {
                        $("#msg > div").remove();
                        var span = "<div class='notification attention png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>请设置阉割日期</div></div>";
                        $("#msg").append(span);
                        return;
                    }
                }
                if (checked == undefined) {
                    checked = false;
                }

                $.ajax2({
                    type: "post",
                    contentType: "application/json",
                    url: "../WebServices/PigletService.asmx/UpdatePiglet",
                    dataType: "json",
                    data: "{ pigletID: '" + pigletId + "',pigTypeStr:'" + pigTypeID + "',phaseFrom:'" + phaseFromId + "',phaseTo:'" + phaseToID
                    + "',pigPenIDStr:'" + pigPenID + "',isCastrate:'" + checked + "',castrateDateStr:'" + castrateDate + "' }",
                    success: function (data) {
                        if (data.d.Flag) {
                            $("#msg > div").remove();
                            var span = "<div class='notification success png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>" + data.d.Message + "</div></div>";
                            $("#msg").append(span);
                        } else {
                            $("#msg > div").remove();
                            var span = "<div class='notification attention png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>" + data.d.Message + "</div></div>";
                            $("#msg").append(span);
                        }
                    },
                    error: function (error) {
                        $("#msg > div").remove();
                        var span = "<div class='notification error png_bg'> <a href='#' class='close'><img src='../resources/images/icons/cross_grey_small.png' title='关闭' alt='关闭' /></a><div>提交失败：" + error.status + "</div></div>";
                        $("#msg").append(span);
                    }

                });



            });


        });
      
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tab-content">
            <fieldset>
             <p>
              <label>母猪耳号:
                 <asp:Label ID="lbBitID" runat="server" Text="Label"></asp:Label>
                 <asp:HiddenField runat="server" ID="hfPigletID" />
               </label>
            </p>
          
            <p>
                <label>猪圈编号：
                    <asp:Label runat="server" ID="lbPigPenId"></asp:Label>
                </label>
            <%--    <asp:DropDownList runat="server" ID="ddlPigPen" AutoPostBack="false"></asp:DropDownList>--%>
            </p>

            <p><label>繁育日期：
                <asp:Label runat="server" ID="lbBirthday"></asp:Label>
                </label>
            </p>

            <p>
              <label>成长阶段:&nbsp;&nbsp;<span><asp:Label ID="lbPhaseName" runat="server"></asp:Label></span>  &nbsp;&nbsp;  
                <a href="javascript:void(0);" id="changPhase">改变仔猪成长阶段?</a>
                </label>
                <asp:HiddenField runat="server" ID="hfPhaseToID" />
                <asp:DropDownList runat="server" ID="ddlPhaseToID"></asp:DropDownList>
             </p>

             <p id="penSetting">
                <label>设定猪圈:</label>
                <asp:HiddenField ID="hfpigPenID" runat="server" />
                <asp:DropDownList runat="server" ID="ddlPigPen"></asp:DropDownList>
             </p>

            <p>
              <label>仔猪品种:&nbsp;&nbsp;<span> <asp:Label runat="server" ID="lbPigType"></asp:Label></span>&nbsp;&nbsp;
               <a href="javascript:void(0);" id="changPigType">改变仔猪品种?</a>
              </label>
               <asp:HiddenField runat="server" ID="hfPigTypeID" />
                <asp:DropDownList runat="server" ID="ddlPigType"></asp:DropDownList>
             </p>
            <p>
              <label>总数量：
              <asp:Label runat="server" ID="lbTotalAccount"></asp:Label>&nbsp;头
            <%--    <asp:TextBox  ID="txtTotalAccount" runat="server" CssClass="text-input small-input" onkeyup="JavaScript:this.value=this.value.replace(/\D/gi,'')" ></asp:TextBox>--%>             
              </label>
            </p>
            <p>
                <label>是否阉割?
                    <asp:CheckBox ID="cbIsCastrate" runat="server" />是
                    <asp:CheckBox ID="cbNoCastrate" runat="server" />否
              <%--  <input type="checkbox" id="cbIsCastrate" value="true" />是
                <input  type="checkbox" id="cbNoCastrate" checked="checked" value="false"/>否--%>
                </label>
            </p>
            <p id="pCastrate">
              <label>阉割日期：
              <asp:TextBox ID="txtCastrateDate" runat="server" CssClass="text-input small-input"></asp:TextBox>
             <%-- <input type="text" id="txtCastrateDate" class="text-input small-input"  />--%>
            </label>
            </p>
            <p>
              <input id="btnSave" value="修改" type="button" />
             </p>
             <p>
                <div id="msg"></div>
             </p>
            </fieldset>
            <div class="clear"></div>
            <!-- End .clear -->
        </div>
    </form>
</body>
</html>
